<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.prime.com.tr/ui">

    <body>

        <ui:composition template="./../../Template/generalTemplate.xhtml">


            <ui:define name="content">
                <h:form id="form" prependId="false">
                    <p:panel id="salesQuotationList" header="Credit Account List" style="height:495px;">

                        <div style="margin-top:20px;margin-left:50px;margin-right:50px;margin-bottom:20px;"> 
                            <p:dataTable id="quotation" dynamic="true" emptyMessage="No Credit Account Exists" value="#{viewPurchasingOrdersManagedBean.getPurchasingOrders()}" var ="o" paginator="true" rows="7">

                                <p:column filterBy="#{o.id}" filterMatchMode="contains" headerText="Order Id"
                                          style="width:200px;">
                                    #{o.id}
                                </p:column>

                                <p:column filterBy="#{o.supplier.id}" filterMatchMode="contains" headerText="Supplier Id">
                                    #{o.supplier.id}
                                </p:column> 

                                <p:column filterBy="#{o.supplier.supplierName}" filterMatchMode="contains" headerText="Supplier Name">
                                    #{o.supplier.supplierName}
                                </p:column>

                                <p:column filterBy="#{o.dateGenerated}" filterMatchMode="contains" headerText="Date Generated">
                                    <h:outputText value="#{o.dateGenerated}">
                                        <f:convertDateTime pattern ="yyyy-MM-dd"/>
                                    </h:outputText>
                                </p:column>

                                <p:column headerText="Action" style="text-align: center;">                                          
                                    <p:commandButton update="outputPanelMain" oncomplete="carDialog.show()" image="ui-icon ui-icon-pencil" title="Edit" style="margin-right: 10px;" >
                                        <f:setPropertyActionListener value="#{o}" target="#{viewPurchasingOrdersManagedBean.selectedPurchasingOrder}" />  
                                    </p:commandButton>

                                </p:column>  

                            </p:dataTable>


                        </div>


                    </p:panel>
                </h:form>
                <h:form prependId="false">
                    <p:dialog header="Edit Credit Account" widgetVar="carDialog" resizable="false" id="carDlg"  
                              showEffect="fade" hideEffect="explode" modal="true" width="1300">  

                        <p:outputPanel id="outputPanelMain">

                            <h:panelGrid id="display"  columns="8" cellpadding="4">  
                                <h:outputText value="Order Id:" style="font-weight:bold"/>  
                                <h:outputText value="#{viewPurchasingOrdersManagedBean.selectedPurchasingOrder.id}" />

                                <h:outputText value="Supplier Id:" style="font-weight:bold"/> 
                                <h:outputText value="#{viewPurchasingOrdersManagedBean.selectedPurchasingOrder.supplier.id}" />

                                <h:outputText value="Supplier Name:" style="font-weight:bold"/> 
                                <h:outputText value="#{viewPurchasingOrdersManagedBean.selectedPurchasingOrder.supplier.supplierName}" />

                                <h:outputText value="Date Generated:" style="font-weight:bold"/> 
                                <h:outputText value="#{viewPurchasingOrdersManagedBean.selectedPurchasingOrder.dateGenerated}" >
                                    <f:convertDateTime pattern ="yyyy-MM-dd"/>
                                </h:outputText>
                            </h:panelGrid>

                            <p:dataTable dynamic="true" emptyMessage="Error: cannot load line itmes" value="#{viewPurchasingOrdersManagedBean.selectedPurchasingOrder.rawMaterialPurchasingOrderLineItems}" var ="o">

                                <p:column filterBy="#{o.id}" filterMatchMode="contains" headerText="Id"
                                          >
                                    #{o.id}
                                </p:column>

                                <p:column filterBy="#{o.rawMaterial.id}" filterMatchMode="contains" headerText="Material Id">
                                    #{o.rawMaterial.id}
                                </p:column> 

                                <p:column filterBy="#{o.rawMaterial.rawMaterialName}" filterMatchMode="contains" headerText="Material Name">
                                    #{o.rawMaterial.rawMaterialName}
                                </p:column>

                                <p:column filterBy="#{o.rawMaterial.leadTime}" filterMatchMode="contains" headerText="Lead Time (week)">
                                    #{o.rawMaterial.leadTime}
                                </p:column>

                                <p:column filterBy="#{o.totalQuantity}" filterMatchMode="contains" headerText="Quantity">
                                    #{o.totalQuantity}
                                </p:column>

                                <p:column filterBy="#{o.supplierLineItemEntity.price}" filterMatchMode="contains" headerText="Price">
                                    #{o.supplierLineItemEntity.price}
                                </p:column>

                                <p:column filterBy="#{o.cumAmount}" filterMatchMode="contains" headerText="Cum Amount">
                                    #{o.cumAmount}
                                </p:column> 

                                <p:column filterBy="#{o.cumAmount}" filterMatchMode="contains" headerText="Cum Amount">
                                    #{o.cumAmount}
                                </p:column> 

                                <p:column headerText="Received" style="text-align: center;">                                          
                                    <p:graphicImage value="/images/check.jpg" style="height:20px; width:20px;" rendered="#{o.received}" />
                                    <p:graphicImage value="/images/error.jpg" style="height:20px; width:20px;" rendered="#{!o.received}" />

                                </p:column> 

                            </p:dataTable>

                        </p:outputPanel>

                    </p:dialog>
                </h:form>
            </ui:define>


        </ui:composition>

    </body>
</html>
